package com.sxbbc.common.core.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.sxbbc.common.core.entity.jz.AppHomeRecommend;
import com.sxbbc.common.core.entity.jz.ProSkuDetail;
import com.sxbbc.common.core.mapper.jz.AppHomeRecommendMapper;
import com.sxbbc.common.core.service.IAppHomeRecommendService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.sxbbc.common.core.service.IProSkuDetailService;
import com.sxbbc.common.core.utils.BasePage;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * <p>
 * 首页推荐商品活动表 服务实现类
 * </p>
 *
 * @author leehao
 * @since 2019-05-25
 */
@Service
public class AppHomeRecommendServiceImpl extends ServiceImpl<AppHomeRecommendMapper, AppHomeRecommend> implements IAppHomeRecommendService {
    @Autowired
    private AppHomeRecommendMapper recommendMapper;
    @Autowired
    private IProSkuDetailService proSkuDetailService;

    @Override
    public IPage<AppHomeRecommend> queryRecommendList(BasePage<AppHomeRecommend> page,AppHomeRecommend recommend) {
        IPage<AppHomeRecommend> list = recommendMapper.queryRecommendList(page,recommend);
        for (AppHomeRecommend record : list.getRecords()) {
            //取创业分
            QueryWrapper<ProSkuDetail> queryWrapper = new QueryWrapper<>();
            queryWrapper.eq("pro_code", record.getProCode());
            List<ProSkuDetail> proSkuDetails = proSkuDetailService.list(queryWrapper);
            record.setPoint(proSkuDetails.get(0).getPoint());
        }
        return list;
    }
}
